//
//  IMChatMessageManager.m
//  ChatMainDemo
//
//  Created by peiw on 16/1/21.
//  Copyright © 2016年 peiw. All rights reserved.
//

#import "IMChatMessageManager.h"
#import "IMChatDisplayData.h"
#import "IMCellDisplayData.h"
#import "IMChatMessage.h"
#import "NSArray+OCMap.h"

@implementation IMChatMessageManager

- (NSArray *)chatDisplayFrom:(NSArray *)messages {
    return [messages oc_map:^id(id element, BOOL *stop) {
        if ([element isKindOfClass:[IMChatMessage class]]) {
            *stop = NO;
            IMChatMessage *msg = (IMChatMessage *)element;
            return [self cellDisplayFrom:msg];
        }else {
            *stop = YES;
            return nil;
        }
    }];
}

- (IMCellDisplayData *)cellDisplayFrom:(IMChatMessage *)msg {
    IMCellDisplayData *cellDisplay = [IMCellDisplayData new];
    cellDisplay.msg = msg;
    switch (msg.msgType) {
        case eTFText:
            cellDisplay.textContent = msg.content;
            break;
        default:
            break;
    }
    if ([msg.userID isEqualToString:msg.peerID]) {
        cellDisplay.direction = Send;
    }else {
        cellDisplay.direction = Recv;
    }
    return cellDisplay;
}

@end
